package resources;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Dialog extends javax.swing.JDialog {
	
	private static final Logger log = LoggerFactory.getLogger(Dialog.class);

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			log.error("", e);
		}
	}


	/**
	 * 
	 */
	private static final long serialVersionUID = -5588214825228719399L;
	private JPanel jPanel1;
	private JButton jButton1;
	private JLabel jLabel1;
	
	
	private int minSize = 118;
	private String textFont = "Arial Rounded MT Bold";
	private String buttonFont = "Arial Rounded MT Bold";
	
	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				Dialog inst = new Dialog(frame,"tralla",1);
				inst.setVisible(true);
			}
		});
	}
	/**
	 * Show dialog frame.
	 * 
	 * @param frame 
	 * @param msg Message to display.
	 * @param serv Integer: 0 - default, 1 - warning, 2 - info, 3 - error
	 */
	public Dialog(JFrame frame,String msg, int serv) {
		super(frame);
		initGUI(msg,serv);
		setVisible(true);
	}
	
	private void initGUI(String msg, int severity) {
		try {
			{
				this.setUndecorated(true);
				this.setResizable(false);
				this.setSize(195, 129);
				{
					jPanel1 = new JPanel();
					jPanel1.setLayout(null);
					getContentPane().add(jPanel1, BorderLayout.CENTER);
					jPanel1.setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, servColor(severity)));
					jPanel1.setPreferredSize(new java.awt.Dimension(187, 100));

					{
						jLabel1 = new JLabel();
						jLabel1.setText(msg);
						jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
						jLabel1.setFont(new java.awt.Font(textFont,0,16));
					}
					{
						jButton1 = new JButton();
						jPanel1.add(jButton1);
						jPanel1.add(jLabel1);
						jLabel1.setBounds(2, 2, countWidth(), 40);
						jButton1.setText("Ok");
						jButton1.setFont(new java.awt.Font(buttonFont,0,14));
						jButton1.setBounds(countWidth()/2-108/2, 60, 108, 27);
						final JDialog tmp = this;
						jButton1.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								tmp.setVisible(false);
								tmp.dispose();
							}
						});
					}
				}
			}
			this.setLocation(UltimateOPS.centerLocation(countWidth(), 100));
			this.setSize(countWidth(), 100);
			jPanel1.setPreferredSize(new java.awt.Dimension(countWidth(), 100));
		} catch (Exception e) {
			log.error("", e);
		}
		
	}
	
	public int countWidth() {
		int tmp=0;
		tmp =jLabel1.getText().length()*9;
		return Math.max(tmp, minSize);
	}
	
	private java.awt.Color servColor(int serv) {
		if (serv>=3) setAlwaysOnTop(true);
		switch (serv) {
		case 0:
			return Color.WHITE;
//			break;
		case 1:
			return new java.awt.Color(255,128,64);
		case 2:
			return Color.GREEN;
		case 3:
			return Color.RED;
		default:
			return Color.black;
		}
		
	}

}

